const registerBox = document.querySelector('.btn')

//1.注册逻辑
//1.1提交账号密码
async function addAcc (data){
    try {
        // console.log(data)是一个对象
        let res = await axios({url:'/register',method:'POST',data:data})
        console.log(res.data)

        // return res.data
    } catch (error) {
        pxmu.fail(error)
    }
    
}
//1.2注册合法性判断
function registerIsLegal(){
    const form = document.querySelector('.register-form')
    const data = serialize(form, { hash: true, empty: true })
    console.log(data)
    if(accountReg.test(data.username) && accountReg.test(data.password) ){
        addAcc(data)
        pxmu.success('恭喜您登陆成功，快去登录吧！')
        setTimeout(()=>{
            location.href='./login.html'
        },1500)
        
    }else{
        pxmu.fail('用户名或密码不合法')
    }
}
//1.3登陆点击事件
registerBox.addEventListener('click',()=>{
    registerIsLegal()
})
